﻿using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace SSC.Utils
{
    public class BoolToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            bool isConnected = false;

            if (value is bool b)
                isConnected = b;
            else if (value is string s && bool.TryParse(s, out var parsed))
                isConnected = parsed;

            return isConnected ? Brushes.Green : Brushes.Red;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
